package com.ozo.boot.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ozo.boot.common.base.model.BaseBatchDTO;
import com.ozo.boot.common.base.model.ResultVO;
import com.ozo.boot.common.log.annotation.OperateLog;
import com.ozo.boot.system.pojo.dto.SysDictTypeQueryDTO;
import com.ozo.boot.system.pojo.dto.SysDictTypeSaveDTO;
import com.ozo.boot.system.entity.SysDictData;
import com.ozo.boot.system.entity.SysDictType;
import com.ozo.boot.system.service.ISysDictTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典类型 前端控制器
 * </p>
 *
 * @author qiangesoft
 * @since 2024-07-11
 */
@Tag(name = "字典管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dict")
public class SysDictTypeController {

    private final ISysDictTypeService sysDictTypeService;

    @OperateLog(value = "添加字典", module = "字典")
    @SaCheckPermission("system:dict:add")
    @Operation(summary = "添加字典")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid SysDictTypeSaveDTO saveDTO) {
        sysDictTypeService.add(saveDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "删除字典", module = "字典")
    @SaCheckPermission("system:dict:remove")
    @Operation(summary = "删除字典")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        sysDictTypeService.remove(batchDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "编辑字典", module = "字典")
    @SaCheckPermission("system:dict:edit")
    @Operation(summary = "编辑字典")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody @Valid SysDictTypeSaveDTO saveDTO) {
        sysDictTypeService.edit(saveDTO);
        return ResultVO.success();
    }

    @SaCheckPermission("system:dict:list")
    @Schema(description = "字典列表")
    @GetMapping("/list")
    public ResultVO<List<SysDictType>> list(SysDictTypeQueryDTO queryDTO) {
        return ResultVO.success(sysDictTypeService.list(queryDTO));
    }

    @Schema(description = "获取字典项")
    @GetMapping("/getDataByCode")
    public ResultVO<List<SysDictData>> getDataByCode(@RequestParam("dictCode") String dictCode) {
        return ResultVO.success(sysDictTypeService.getDataByCode(dictCode));
    }

}
